package com.leetcode.LC;

public class LC824 {
    public String toGoatLatin(String S) {

        String[] s = S.split(" ");
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length; i++) {
            String s1 = toGoatWord(s[i], i + 1);
            builder.append(s1 + " ");
        }
        return builder.toString().substring(0, builder.length() - 1);
    }

    public String toGoatWord(String s, int i) {
        StringBuilder builder;
        if ("aAeEiIoOuU".contains(s.charAt(0) + "")) {
            builder = new StringBuilder(s);
            builder.append("ma");
            for (int j = 0; j < i; j++) {
                builder.append('a');
            }
        } else {
            char tmp = s.charAt(0);
            String substring = s.substring(1, s.length());
            builder = new StringBuilder(substring);
            builder.append(tmp);
            builder.append("ma");
            for (int j = 0; j < i; j++) {
                builder.append('a');
            }
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new LC824().toGoatLatin("I speak Goat Latin"));
    }
}
